package net.dopan.pigframe.discovery.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;

/**
 * @Package: net.dopan.pigframe.discovery.config
 * @Title: WebSecurityConfig
 * @Description: 安全配置
 * @author: 刘宽
 * @date: 2018-09-05 13:23
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
        //关闭csrf
        http.csrf().disable();
        //注意：为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,如果是form方式,不能使用url格式登录
        //开启认证
        http.authorizeRequests()
                //.antMatchers("/actuator/**").permitAll() // actuator监控
                .anyRequest()
                .authenticated()
                .and().httpBasic();
    }

}